package com.lucifer.cloud.boot.blog.chat.config;

import org.springframework.ai.retry.RetryUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestClient;

/**
 * @author lucifer
 * @date 2025/3/12 10:19
 */
@Configuration
public class RestClientConfig {


    String baseUrl = "https://open.bigmodel.cn/api/paas";

    @Value("${spring.ai.zhipuai.api-key}")
    private String zhiPuAiToken;

    @Bean("zhiPuAiRestClient")
    public RestClient zhiPuAiRestClient() {
        return RestClient.builder().baseUrl(baseUrl).defaultHeaders(
                (h) -> {
                    h.setContentType(MediaType.APPLICATION_JSON);
                    h.setBearerAuth(zhiPuAiToken);
                }
        ).defaultStatusHandler(RetryUtils.DEFAULT_RESPONSE_ERROR_HANDLER).build();
    }
}
